<?php
namespace app\forum\controller;
use app\forum\controller\SiteController;
/**
 * 站点首页
 */

class IndexController extends SiteController {

	/**
     * 主页
     */
    public function index(){
        //获取首页模块
        $where=array();
        $where['index'] = 1;
        $info = target('forum/Menu')->getWhereInfo($where);
        if(empty($info)){
            $tplArray = array();
            $tplArray['app'] = 'forum';
            $tplArray['controller'] = 'plate';
            $tplArray['action'] = 'index';
            $GLOBALS['tplArray'] = $tplArray;
            target('forum/plate','controller')->index();
            exit;
        }
        $var = explode('_', $info['url'], 2);
        if($var[0] == 'pages'){
            $tplArray = array();
            $tplArray['app'] = 'forum';
            $tplArray['controller'] = 'Page';
            $tplArray['action'] = 'index';
            $GLOBALS['tplArray'] = $tplArray;
            $_GET['page_id'] = $var[1];
            target('forum/Page','controller')->index();
        }else{
            $urlInfo = service($var[0],'Menu','getForumMenu');
            $module = $urlInfo[$var[1]]['url'];
            $module = explode('/', $module);
            //设置模板路径
            $tplArray = array();
            $tplArray['app'] = $module[0];
            $tplArray['controller'] = $module[1];
            $tplArray['action'] = $module[2];
            $GLOBALS['tplArray'] = $tplArray;
            target($module[0].'/'.$module[1],'controller')->$module[2]();
        }
    }

    /**
     * 页面不存在
     */
    public function error404(){
    	$this->siteDisplay();
    }
}